    <script type="text/javascript" src="<?=BASEURL.JS_DIR?>jquery.js" ></script>
    <script type="text/javascript" src="<?=BASEURL.JS_DIR?>jquery_std.js" ></script>
    <script type="text/javascript" src="<?=BASEURL.JS_DIR?>common.js" ></script>
    <script type="text/javascript" src="<?=BASEURL.JS_DIR?>popin.js" ></script>
    <script type="text/javascript" src="<?=BASEURL.JS_DIR?>toolbar.js" ></script>
    <script type="text/javascript">
    
    //data from server
    myData = {};
    myData.baseUrl  = "<?=site_url('');?>";
    myData.isLogged = <?=$isLogged+0?>;
    myData.pageName = "<?=$pagename?>";    

    function onResize()
    {
        size=$.windowSize();
        $("#textarea1").height(size.h-215+"px");       
    }

    function btLinks() {
        popIn(420,235,"#pop_editlink",'Create a new link');
        $("#popInContent #texttodisplay").val(tb_getSelection(document.myForm.content));  
                $("#popInContent input[@type='radio']").click(function(){
            $("#popInContent div").removeClass("select");
            $(this).parent().parent('div').addClass("select");
            });    
    }
    
    function btBloc() {
        popIn(400,179,"#pop_addbloc",'Create a new link');

    }
    
    function gotoVersion() {
    	var ver=$("#selectVersion").get(0);
    	window.location.href=site_url('/admin/wikimgr/edit/'+ver.options[ver.selectedIndex].value);
    }
    
    function changeTemplate() {
    	var frm=$("#frmTemplate").get(0);
    	var ver=$("#selectTemplate").get(0);
    	frm.value=ver.options[ver.selectedIndex].value;
    }
    
    function updateTags() {
    	$("#frmTags").val($("#popInContent textarea").val());
    }
    
    function btMedia() {
        popIn(610,452,site_url('/admin/mediamgr/'),"media manager");
    }
    
    function insertLinkInCode() {
      var linktype=$("#popInContent input[@type='radio']:checked").val();
      switch (linktype)
        {
          case 'wikipage':
            link=$('#popInContent #wikipage option:selected').val();
            break;
          case 'webadress':
            link=$('#popInContent #webadress').val();
            break;
          case 'email':
            link='mailto:'+$('#popInContent #emailadress').val();
            break;
        }
       var descr=$("#popInContent #texttodisplay").val();
       if (descr!="") descr="|"+descr;
       tb_replaceSelection(document.myForm.content,'[['+link+descr+']]');
    }
    
    function insertBlocInCode() {
        var blc=$("#selectBloc").get(0);
    	tb_wrapSelection(document.myForm.content,"\n[bloc|"+blc.options[blc.selectedIndex].value+"]\n","\n[/bloc]\n");
    }

   
    $(document).ready(function() {
       
       thisForm=document.myForm;
       $(window).resize(onResize);
       onResize();
       
       //buttons & selects
       
       $("#btVersions").click(function() {
       		popIn(260,96,"#pop_versions",'Choose a version');  
       });
       
        $("#btTemplate").click(function() {
       		popIn(400,179,"#pop_template",'Choose a template');

       });      
       
       $("#btTags").click(function() {
       		popIn(400,180,"#pop_tags",'Choose a template');
    		$("#popInContent textarea").html($("#frmTags").val());

       });    
       
       $("#btLogout").click(function(){
            logout(site_url('/wiki/read/<?=$pagename;?>')); 
       });
       
       $('#btHelp').click( function(){
            popIn(400,500,site_url('/wiki/readpart/help'),'HELP');
       });
       
       $('#btCreatePage').click( function(){
               var nompage = normalize_str(prompt("nom de la nouvelle page"));
               if (nompage != null) 
                   window.location.href=site_url('/admin/wikimgr/edit/'+nompage);
                   
       });
       
       $('#btDeletePage').click( function(){
              if (confirm ("are you sure ?"))
                  window.location.href=site_url('/admin/wikimgr/delete/'+myData.pageName);
       });

       
       $("#textarea1").toolbar({buttons: [
        {name:'italic',desc:'mettre en italique',lft:'::',rgt:'::' },
        {name:'bold',desc:'mettre en italique',lft:'**',rgt:'**' },
        {name:'underline',desc:'mettre en italique',lft:'__',rgt:'__' },
        {name:'separ'}, 
        {name:'h1',desc:'titre',lft:'\\n!',rgt:'\\n' },
        {name:'h2',desc:'sous-titre',lft:'\\n!!',rgt:'\\n' },
        {name:'h3',desc:'sous-titre 2',lft:'\\n!!!',rgt:'\\n' },
        {name:'separ'},
        {name:'bloc',desc:'add a block',fn:'btBloc' },
        {name:'link',desc:'make a link',fn:'btLinks' },
        {name:'media',desc:'add a media file',fn:'btMedia' }
         ],
         buttonClass: 'button',
         mainClass: 'toolbar',
         separ: 3
       });
     
    });
    
    </script>
